﻿Imports System.Data.OleDb
Imports System.Data
Public Class Editprofile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            Dim tUsername As String = Context.User.Identity.Name
            Dim conn = New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("fishconn").ConnectionString)
            conn.Open()
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT FirstName, LastName, EmailAddress, Address, State, Country, Gender, DateofBirth, PhoneNumber, Description, ProfilePicturesmall, Interest, DisplayMessage FROM tblProfile WHERE ([UserName] = ?);", conn)
            cmd.Parameters.AddWithValue("@username", tUsername)
            Dim rs As OleDbDataReader = cmd.ExecuteReader
            If rs.Read() Then
                txtFname.Text = rs("FirstName").ToString
                txtLname.Text = rs("LastName").ToString
                txtemail.Text = rs("EmailAddress").ToString
                txtaddress.Text = rs("Address").ToString
                txtState.Text = rs("State").ToString
                txtcountry.Text = rs("Country").ToString
                If rs(6).ToString = "F" Then
                    cbxSex.SelectedIndex = 1
                Else
                    cbxSex.SelectedIndex = 0
                End If
                Dim str As String
                str = rs(7).ToString
                If str <> "" Then
                    Dim datebirth As Date
                    datebirth = rs(7)
                    txtDOB.Text = datebirth.ToString("yyyy-MMM-dd")
                End If

                txtphone.Text = rs(8).ToString
                txtDescription.Text = rs(9).ToString
                txtdisplaymessage.Text = rs(12).ToString
                TxtInterest.Text = rs(11).ToString
            End If
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim tUsername As String = Context.User.Identity.Name
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("fishconn").ConnectionString)
        Dim SqlString As String = "UPDATE tblProfile SET tblProfile.FirstName = @FirstName, tblProfile.LastName = @LastName, tblProfile.EmailAddress = @EmailAddress, tblProfile.Address = @Address, " & _
                                   "tblProfile.State = @State, tblProfile.Country = @Country, tblProfile.Gender = @Gender, tblProfile.DateofBirth = @DateofBirth, " & _
                                   "tblProfile.PhoneNumber = @PhoneNumber, tblProfile.Description = @Description, tblProfile.Interest = @Interest, tblProfile.DisplayMessage = @DisplayMessage WHERE (((tblProfile.UserName) Like @UserName));"

        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        Dim pfname As String = txtFname.Text
        cmd.Parameters.AddWithValue("@FirstName", txtFname.Text.ToString)
        cmd.Parameters.AddWithValue("@LastName", txtLname.Text.ToString)
        cmd.Parameters.AddWithValue("@EmailAddress", txtemail.Text)
        cmd.Parameters.AddWithValue("@Address", txtaddress.Text.ToString)
        cmd.Parameters.AddWithValue("@State", txtState.Text)
        cmd.Parameters.AddWithValue("@Country", txtcountry.Text)
        cmd.Parameters.AddWithValue("@Gender", cbxSex.Text)
        cmd.Parameters.AddWithValue("@DateofBirth", txtDOB.Text)
        cmd.Parameters.AddWithValue("@PhoneNumber", txtphone.Text)
        cmd.Parameters.AddWithValue("@Description", txtDescription.Text)
        cmd.Parameters.AddWithValue("@Interest", TxtInterest.Text)
        cmd.Parameters.AddWithValue("@DisplayMessage", txtdisplaymessage.Text)
        cmd.Parameters.AddWithValue("@UserName", tUsername)
        oleDbConn.Open()
        If cmd.ExecuteNonQuery() = 1 Then
            Response.Redirect("~/Account/manage.aspx")
        End If
    End Sub
End Class